package com.neusoft.util;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.neusoft.mapper.BusinessMapper;
import com.neusoft.po.Business;
import com.neusoft.po.Food;

/**
 * @author chj
 * @date 2024年9月6日
 */
/**
 * 在静态工具类中注入mapper的方式示例
 */
@Component
public class Lock {
	@Autowired
	private BusinessMapper businessMapper;

	private static Lock Lock;

	@PostConstruct
	public void init() {
		Lock = this;

		Lock.businessMapper = this.businessMapper;
	}

	public static boolean BusinessLock(Business business) {
		// 验证商家Id和password匹配
		// 不匹配不能修改商家的信息，对食物，商家信息修改时应该进行调用进行判断
		String passwordIn = business.getBusinessPassword();
		String passwordDB = Lock.businessMapper.getBusinessById(business.getBusinessId()).getBusinessPassword();
		return passwordDB.equals(passwordIn);
	}

	public static boolean FoodCountLock(Integer foodCount) {
		// 验证食物数量小于对应ordersdetailet的quantity
		// 用于点餐进行食物增加的验证，并且在save时也进行验证
		return foodCount >= 0;
	}

	public static boolean EmptyLock(Integer num) {
		// 用于实现将密码单向加密后再存⼊数据库的功能。
		return num > 0;
	}
}
